import 'package:get/get.dart';
import 'package:laos_mall/app_route.dart';
import 'package:laos_mall/common/base/base_controller.dart';
import 'package:laos_mall/common/utils/http_util.dart';
import 'package:laos_mall/models/home/product_detail_model.dart';
import 'package:laos_mall/pages/main/catergory/sku/view.dart';
import 'package:laos_mall/pages/main/logic.dart';

class ProductDetailLogic extends BaseController {
  ProductDetailModel? model;
  int? skuId;
  @override
  initConfig()async{
    var arg = Get.arguments;
    skuId = arg["sku_id"];
    var res = await HttpUtil.restApi.productDetail(arg);
    model = res.data;
    if(model?.sku_list != null){
      skuId ??= model?.sku_list?.firstOrNull?.sku_id;
    }
    update();
  }

  jumpToSku(){
    Get.bottomSheet(SkuPage());
  }

  goToHome(){
    // logic.tabController.animateTo(0);
    // 切换到根页面（首页），但不影响路由栈
    final logic = Get.find<MainLogic>();
    logic.index.value = 0;
    Get.until((route) => route.isFirst);
  }
  goToCart(){
    // final logic = Get.find<MainLogic>();
    // logic.tabController.animateTo(3);
    final logic = Get.find<MainLogic>();
    logic.index.value = 3;
    Get.until((route) => route.isFirst);
  }

  clickCollect(){

  }

  addToCart(){
    jumpToSku();
  }

  payNow(){
    jumpToSku();
  }
}
